import { isArray, isObject, isString } from "../shared/index"
import { ShapeFlags } from "../shared/shapeFlags"

export function createVNode(type,props: any={},children={}) {

  

  const shapeFlag = isString(type) ? 
        ShapeFlags.ELEMENT :
        isObject(type) ? 
        ShapeFlags.STATEFUL_COMPONENT :  0

  const vnode = {
    type,
    props,
    children,
    component: null, // 组件的实例
    el: null, // 虚拟节点要和真实节点做一个映射关系
    key: props.key,
    shapeFlag  // vue3里面非常优秀的做法，虚拟节点的类型
  }

  if (isArray(children)) {
    vnode.shapeFlag |= ShapeFlags.ARRAY_CHILDREN
  } else {
    vnode.shapeFlag |= ShapeFlags.TEXT_CHILDREN
  }

  return vnode
}